package com.st;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
import org.springframework.web.util.pattern.PathPatternParser;

import java.time.ZonedDateTime;

/**
 * <p>title: com.wfx</p>
 * author zhuximing
 * description:
 */
@SpringBootApplication
@EnableDiscoveryClient
public class GateWapApp {

    public static void main(String[] args) {
        System.out.println(ZonedDateTime.now());
        SpringApplication.run(GateWapApp.class,args);
    }


    @Bean
    public CorsWebFilter corsFilter() {
        CorsConfiguration config = new CorsConfiguration();
        config.addAllowedMethod("*");
        config.addAllowedOrigin("*");
        config.addAllowedHeader("*");

        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
        source.registerCorsConfiguration("/**", config);

        return new CorsWebFilter(source);
    }

//    @Bean
//    @Order(1)
//    public GlobalFilter  aFilter(){
//
//        return  new GlobalFilter() {
//            @Override
//            public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
//
//                System.out.println("A come in ");
//
//
//                return chain.filter(exchange).then(   Mono.fromRunnable(()->{
//                    System.out.println("A post come in");
//
//                }));
//            }
//        };
//    }
//
//
//    @Bean
//    @Order(2)
//    public GlobalFilter  bFilter(){
//
//        return  new GlobalFilter() {
//            @Override
//            public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
//
//                System.out.println("b come in ");
//
//
//                return chain.filter(exchange).then(   Mono.fromRunnable(()->{
//                    System.out.println("b post come in");
//
//                }));
//            }
//        };
//    }


}
